//
//  FMDBManager.m
//  zhongwulegou
//
//  Created by qianfeng on 15/9/22.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "FMDBManager.h"

@implementation FMDBManager

//数据库类单例
+(instancetype)shareInstance
{
    static FMDBManager *manager = nil;
    
    @synchronized(self)
    {
        if (manager == nil) {
            manager = [FMDBManager new];
        }
    }
    return manager;
}

-(instancetype)init
{
    if (self = [super init]) {
        //初始化数据库
        NSString *filePath = [NSHomeDirectory() stringByAppendingString:@"/Documents/shopxinyi.db"];
//        NSLog(@"filePath==%@",filePath);
        
        self.dataBase = [FMDatabase databaseWithPath:filePath];
        
        if (![self.dataBase open]) {
            NSLog(@"数据库 shopxinyi 打开失败");
        }
        if (![self.dataBase executeUpdate:@"create table if not exists User(id integer primary key autoincrement,client text, password text, username text, key text)"]) {
            NSLog(@"创建表 User 失败");
        }
    }
    return self;
}

@end
